using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Reflection;


// [CreateAssetMenu(fileName = "CardData", menuName = "CardSystem/CardData")]
// public class CardData : ScriptableObject
public class CardData
{
    public int id;
    public string card_name;
    public string name = "CardData";
    public string description;

    public string icon_path;
    
    public int star_level = 1;
    public string effect_type_name;
    
    public int attack;
    public int hp;

    public string info()
    {
        var res = $"CardData(id={id}, card_name={card_name}, description={description}, attack={attack}, hp={hp}, card_type={card_type})";
        return res;
    }

    public override string ToString()
    {
        // return base.ToString();
        return this == null? base.ToString(): info();
    }

    public CardTypeEnum card_type = CardTypeEnum.soldier;

    public int cost_value;
    public CostTypeEnum cost_type = CostTypeEnum.mp;

    [Header("使用目标数量")]
    public int use_target_num = 0;

    public void clear_effect_callbacks()
    {
        // 获取当前类的所有公有实例属性
        PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
        
        foreach (PropertyInfo property in properties)
        {
            // 检查属性类型是否为 BaseCardEffectModule
            if (property.PropertyType == typeof(BaseCardEffectModule) && property.CanWrite)
            {
                property.SetValue(this, null); // 将属性置空
            }
        }
        
        // 如果有字段需要处理，也可以类似操作
        FieldInfo[] fields = GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
        foreach (FieldInfo field in fields)
        {
            if (field.FieldType == typeof(BaseCardEffectModule))
            {
                field.SetValue(this, null); // 将字段置空
            }
        }
        
       // OnAppearInStore = null;
       // OnCreate = null;
       // OnRemove = null;
       // OnTick = null;
       // OnUse = null;
       // OnBuy = null;
       // OnGetInHand = null;
       // OnCreateSoldier = null;
       // OnHit = null;
       // OnBeHurt = null;
       // OnKill = null;
       // OnBeKill = null;
       // OnEventCallBack = null;
    }
    // 回调点
    public BaseCardEffectModule OnCreate { get; set; }
    public BaseCardEffectModule OnRemove  { get; set; }
    public BaseCardEffectModule OnTick  { get; set; }
    
    public BaseCardEffectModule OnUse  { get; set; }
    
    public BaseCardEffectModule OnBuy  { get; set; }
    public BaseCardEffectModule OnGetInHand { get; set; }
    public BaseCardEffectModule OnCreateSoldier  { get; set; }  // 随从卡牌创建随从时
    
    // --- 场景回调
    public BaseCardEffectModule OnBeginStore { get; set; }  // 进入商店场景
    public BaseCardEffectModule OnBeginBattle { get; set; }  // 进入战斗场景

    public BaseCardEffectModule OnAppearInStore  { get; set; }  // 出现在商店
    public BaseCardEffectModule OnAppearInBattle { get; set; }  // 出现在战场

    public BaseCardEffectModule OnEndStore { get; set; }  // 结束商店场景 --- 这时候应该记录当前buff和属性, 每回合开始时重置. 注意战斗中能保留的buff.
    public BaseCardEffectModule OnEndBattle { get; set; }  // 结束战斗场景

    // 伤害回调点
    public BaseCardEffectModule OnHit { get; set; }
    public BaseCardEffectModule OnBeHurt { get; set; }
    public BaseCardEffectModule OnKill { get; set; }
    public BaseCardEffectModule OnBeKill { get; set; }
    
    // 事件代码回调
    public BaseCardEffectModule OnEventCallBack { get; set; }
}
